{include file="public/header" /}
<div class="index_html houtai">
    {include file="public/second_header" /}

<!-- 地下内容的开始 -->
<div class="backgroud_content new_huanzhe_record">
<!-- 左侧的开始 -->
    {include file="public/nav" /}
<!-- 左侧的结束 -->

<!-- 右侧的开始 -->
<div class="right_bar hou_jiluxiangqing add_jilu">
    {include file="public/go_back" /}
    <div class="jcjl_detail">
        <div class="list_box">
            <div class="top_dec">
                <span class="theme">{$breadcrumb}</span>
            </div>
            <form action="" class="horizontal" method="post" role="form" >
            <div class="content">
                <div class="msg">
                    <ul>
                        <li>
                            <span>检查编号：</span>
                            <div class="right">
                                <input type="text" name="case_num"value="{$patientcase_info['case_num'] ?? ''}" placeholder="如：20151515">
                            </div>
                        </li>
                        <li class="name">
                            <span>姓名：</span>
                            <em>{$patient_info['name']}</em>
                            <input type="hidden" value="{$patient_info['id']}" name="patient_id">
                        </li>
                        <li>
                            <span>检查类型：</span>
                            <div class="right">

                                <select name="patient_case_type" >

                                    {if condition="$case_select"}
                                    {foreach name="case_select" item="vo"}
                                    <option value="{$vo['id']}" {if condition="isset($patientcase_info['patient_case_type']) && $patientcase_info['patient_case_type'] eq $vo['id']"}selected{/if}>{$vo['name']}</option>
                                    {/foreach}
                                    {else/}
                                    <option value="" disabled="">请选择</option>
                                    {/if}

                                </select>
                            </div>
                        </li>
                        <li class="buwei">
                            <span>检查部位：</span>
                            <div class="right_box">
                                <div class="top">
                                    {if condition="isset($patientcase_info['patient_part_lat']) && $patientcase_info['patient_part_lat']"}

                                    <div class="li_1">
                                        <div class="right">
                                            <select name=""  class="change_part">
                                                <!--  <option value="0" disabled="">请选择</option>-->

                                                {if condition="$case_depart"}

                                                {foreach name="case_depart" item="vo"}
                                                <option value="{$vo['name']}" {if condition="$patient_part_lat_1['part'] eq $vo['name']"}selected{/if}>{$vo['name']}</option>
                                                {/foreach}

                                                {else/}

                                                <option value="" disabled="">请选择</option>
                                                {/if}

                                            </select>
                                           </div>
                                        <span class="weidu">维度：</span>
                                        <div class="right right_2">
                                            <select name=""  class="change_lat">
                                                {if condition="$case_lat"}

                                                {foreach name="case_lat" item="vo"}
                                                <option value="{$vo['name']}" {if condition="$patient_part_lat_1['lat'] eq $vo['name']"}selected{/if}>{$vo['name']}</option>
                                                {/foreach}

                                                {else/}

                                                <option value="" disabled="">请选择</option>
                                                {/if}
                                            </select>

                                        </div>


                                        <div class="add_box">
                                            <span class="option_btn"></span>
                                        </div>
                                        </div>
                                        <input type="hidden" name="patient_part_lat[1][lat]" class="patient_lat" value="{$patient_part_lat_1['lat']}">
                                        <input type="hidden" name="patient_part_lat[1][part]" class="patient_part" value="{$patient_part_lat_1['part']}">

                                        <!-------第一个部位维度---------->

                                    {else/}

                                    <div class="li_1">
                                        <div class="right">
                                            <select name="" class="change_part">

                                                {if condition="$case_depart"}

                                                {foreach name="case_depart" item="vo"}
                                                <option value="{$vo['name']}" >{$vo['name']}</option>
                                                {/foreach}


                                                {else/}

                                                <option value="" disabled="">请选择</option>
                                                {/if}



                                            </select>

                                        </div>
                                        <span class="weidu">维度：</span>
                                        <div class="right right_2">
                                            <select name="" class="change_lat">

                                                <!-- <option value="0" disabled="">请选择</option>-->
                                                {if condition="$case_lat"}
                                                {foreach name="case_lat" item="vo"}
                                                <option value="{$vo['name']}" >{$vo['name']}</option>
                                                {/foreach}

                                                {else/}
                                                <option value="" disabled="">请选择</option>
                                                {/if}

                                            </select>

                                        </div>


                                        <div class="add_box">
                                            <span class="option_btn"></span>
                                        </div>

                                    </div>

                                <!-------第一个部位维度---------->
                                        <input type="hidden" name="patient_part_lat[1][lat]"class="patient_lat"  value="{if condition='isset($case_lat[0]["name"])'}{$case_lat[0]['name']} {else/} ''{/if}">
                                        <input type="hidden" name="patient_part_lat[1][part]" class="patient_part"  value="{if condition='isset($case_depart[0]["name"])'}{$case_depart[0]['name']} {else/} ''{/if}">


                                {/if}
                                </div>



                                <!-------第一个部位维度---------->

                                    <div class="li_s">
                                        {if condition="isset($patient_part_lat) && $patient_part_lat"}

                                        {foreach name="$patient_part_lat" item="vo" key="k"}

                                        <div class="new_list top">
                                            <div class="right">
                                                <select name=""  class="change_part">
                                                    <option value="{$vo['part']}" >{$vo['part'] }</option>
                                                    {if condition="$case_depart"}
                                                    {foreach name="case_depart" item="svo"}
                                                    {if condition="$svo['name'] neq $vo['part']"}
                                                    <option value="{$svo['name']}" >{$svo['name']}</option>
                                                    {/if}
                                                    {/foreach}
                                                    {/if}

                                                </select>

                                            </div>
                                            <span class="weidu">维度：</span>
                                            <div class="right right_2"  >
                                                <select name="" class="change_lat">
                                                    <option value="{$vo['lat'] }" >{$vo['lat'] }</option>
                                                    {if condition="$case_lat"}
                                                    {foreach name="case_lat" item="svo"}
                                                    {if condition="$svo['name'] neq $vo['lat']"}
                                                    <option value="{$svo['name']}" >{$svo['name']}</option>
                                                    {/if}
                                                    {/foreach}
                                                    {/if}
                                                </select>

                                            </div>


                                            <div class="add_box">
                                                <span class="option_btn"></span>
                                            </div>
                                            <input type="hidden" name="patient_part_lat[{$k}][lat]" class="patient_lat" value="{$vo['lat']}">
                                            <input type="hidden" name="patient_part_lat[{$k}][part]"  class="patient_part" value="{$vo['part']}">

                                        </div>

                                        {/foreach}
                                        {/if}

                                    </div>
                                </div>

                        </li>
                        <li>
                            <span>检查时间：</span>
                            <div class="right">
                                 <script type="text/javascript">
                                     $(function(){
                                         $('.end_date_picker').date_input();
                                     })
                                 </script>
                                <div style="" class="input_box">
                                    <input  style="" type="text" class="end_date_picker" value="{$patientcase_info['check_time'] ?? ''}" name="check_time" id="new_date">
                                </div>
                                <script>
                                    //创建一个当前日期对象
                                    var now = new Date();
                                    //格式化日，如果小于9，前面补0
                                    var day = ("0" + now.getDate()).slice(-2);
                                    //格式化月，如果小于9，前面补0
                                    var month = ("0" + (now.getMonth() + 1)).slice(-2);
                                    //拼装完整日期格式
                                    var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
                                    //完成赋值
                                    if(isset($patientcase_info['check_time']) && $patientcase_info['check_time']){

                                    }else{
                                        $('#new_date').val(today);
                                    }

                                </script>
                            </div>
                        </li>
                        <li class="reslut">
                            <span>检查结果：</span>
                            <div class="right">
                                <textarea name="check_result" id="" cols="30" rows="10">{$patientcase_info['check_result'] ?? ''}</textarea>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
            <!--  列表的开始 -->
            <div class="list">
                <div class="data data_1">
                    <p >上传影像</p>
                    <div class="img_box" id="img_box">
                        <div class="up_box" id="pic">
                            <div class="up_btn">
                                <span>上传照片</span>
                            </div>
                        </div>
                        {if condition="isset($electronic_report_arr) && $electronic_report_arr"}
                        {foreach $electronic_report_arr as $key=>$value}
                        <div class="pic_dec">
                            <img src="{$value}" alt="">
                            <input type="hidden" value="{$value}" name="electronic_report[]">
                           <em class="remove-img"></em>
                        </div>
                        {/foreach}
                        {/if}


                    </div>
                </div>
                <!-- 电子胶片的 开始-->
                <div class="data data_2 buwei_dec">
                    <div class="tit_top">
                        <p class="theme">电子胶片</p>
                        <div class="tit_right">
                            <!-- 右面的 按钮 开始 -->
                            <a  class="add_btn">新建分组</a>
                            <a  class="cancle_btn">删除分组</a>
                        </div>
                    </div>

                    <!-------------部位1----------------->

                    {if condition="isset($electronic_film_arr) && $electronic_film_arr"}

                    {foreach name="$electronic_film_arr" item="vo" key="key"}
                    <div class="pic_box" id="img_box_film_{$key}">
                        <span>部位： </span>
                        <div class="mini_theme">
                            <input type="text" name="electronic_film[{$key}][report_name]" value="{$vo['report_name']}">
                        </div>
                        <em class="decrease_btn"></em>
                        <div class="jiaopian_box">
                            <div class="up_box" id="electronic_film_{$key}">
                                <div class="up_btn">
                                    <span>上传照片</span>
                                </div>
                            </div>
                        </div>
                        {foreach name="$vo['img']" item="svo" key="skey"}
                        <div class="pic_dec_1">
                            <div class="dcmDel"><img src="__STATIC__/index/imgs/dcmDel.png"></div>
                            <div id="dwv_{$key}_{$skey}">
                                <div class="layerContainer">
                                    <canvas class="imageLayer"></canvas>
                                </div>
                            </div>
                            <input type="hidden" value="{$svo}" name="electronic_film[{$key}][img][]">
                        </div>
                        <script>

                        $(function() {
                            n = "{$key}";
                            k = "{$skey}";
                            url = "{$svo}";
                            init_dicom(n,k,url)
                        })
                        $('body').on('click', '.dcmDel', function(){
                            $(this).parent().remove();
                            uploader.trigger('fileDequeued');
                        })


                        </script>
                        {/foreach}
                    </div>



                    <script src="__STATIC__/common/webuploader/webuploader.min.js"></script>
                    <script type="text/javascript" src="__STATIC__/common/dwv/dwv-0.22.0.min.js"></script>
                    <script>

                        //图片上传
                        var uploader = WebUploader.create({
                            auto: true,
                            swf:'__ASSETS__/lib/webuploader/Uploader.swf',
                            server:'{:url("common/upload/uploadFile")}',
                            pick:'#electronic_film_{$key}',
                            fileVal:'pic',
                            fileNumLimit:'5',
                            duplicate :true,
                            accept : {
                                title:"格式不正确",
                            extensions:"dcm"
                             }

                        })



                        uploader.on('uploadSuccess', function(file, response){
                            //console.log(response);
                            if (response.error == 0) {

                                //获取当前pic个数
                                var length = $(".pic_dec_{$key}").length;

                                var html = '<div class="pic_dec_{$key}">';
                                html += ' <div id="dwv_1_'+length+'">';
                                html += ' <div class="layerContainer">';
                                html += ' <canvas class="imageLayer"></canvas>';
                                html += ' </div>';
                                html += ' </div>';
                                html += ' </div>';
                                html += '<input type="hidden" class="body_album" name="electronic_film[{$key}][img][]" value="'+response.url+'"/>';
                                $('#img_box_film_1').append(html);
                                url = response.url;
                                init_dicom({$key},length,url)
                            }
                        });

                        uploader.on("error", function (type) {
                            if (type == "Q_TYPE_DENIED") {
                                layer.msg("请上传DCM格式文件");
                            }else {
                                layer.msg("上传出错！请检查后重新上传！错误代码"+type);
                            }

                        });
                        //删除图片
                        $('body').on('click', '.dcmDel', function(){
                            $(this).parent().remove();
                            uploader.trigger('fileDequeued');
                        })


                    </script>

                    {/foreach}


                    <!------------部位1------------------>
                    {else/}
                    <!-------------部位1----------------->


                    <!-------------部位1----------------->
                    <div class="pic_box" id="img_box_film_1">
                        <span>部位： </span>
                        <div class="mini_theme">
                            <input type="text" name="electronic_film[1][report_name]">
                        </div>
                        <em class="decrease_btn"></em>
                        <div class="jiaopian_box">
                            <div class="up_box" id="electronic_film_1">
                                <div class="up_btn">
                                    <span>上传照片</span>
                                </div>
                            </div>

                        </div>


                    </div>
                    <script src="__STATIC__/common/webuploader/webuploader.min.js"></script>
                    <script type="text/javascript" src="__STATIC__/common/dwv/dwv-0.22.0.min.js"></script>
                    <script>

                        //图片上传
                        var uploader = WebUploader.create({
                            auto: true,
                            swf:'__ASSETS__/lib/webuploader/Uploader.swf',
                            server:'{:url("common/upload/uploadFile")}',
                            pick:'#electronic_film_1',
                            fileVal:'pic',
                            fileNumLimit:'5',
                            duplicate :true,
                            accept : {
                                title:"格式不正确",
                                extensions:"dcm"
                            }

                        })

                        uploader.on('uploadSuccess', function(file, response){
                            //console.log(response);
                            if (response.error == 0) {

                                //获取当前pic个数
                                var length = $(".pic_dec_1").length;
                                var length = Number(length)+1;
                                var html = '<div class="pic_dec_1">';
                                html += '<div class="dcmDel"><img src="__STATIC__/index/imgs/dcmDel.png"></div>';
                                html += ' <div id="dwv_1_'+length+'">';
                                html += ' <div class="layerContainer">';
                                html += ' <canvas class="imageLayer"></canvas>';
                                html += ' </div>';
                                html += ' </div>';
                                html += ' </div>';
                                html += '<input type="hidden" class="body_album" name="electronic_film[1][img][]" value="'+response.url+'"/>';
                                $('#img_box_film_1').append(html);
                                url = response.url;

                                init_dicom(1,length,url)

                            }
                        });


                        uploader.on("error", function (type) {
                            if (type == "Q_TYPE_DENIED") {
                                layer.msg("请上传DCM格式文件");
                            } else if (type == "Q_EXCEED_SIZE_LIMIT") {
                                layer.msg("文件大小不能超过2M");
                            }else {
                                layer.msg("上传出错！请检查后重新上传！错误代码"+type);
                            }

                        });
                        //删除图片
                        $('body').on('click', '.dcmDel', function(){
                            $(this).parent().remove();
                            uploader.trigger('fileDequeued');
                        })


                    </script>

                    {/if}



                    <!------------部位1------------------>
                </div>



                <!-- 电子胶片的 结束-->

                <!-- 录入医生 -->
                <div class="enter_doctor">
                    <p>录入医生：<span>{$patientcase_info['doctor_name'] ?? $adminName }</span></p>
                    <input type="hidden" name="doctor_id" value="{$patientcase_info['doctor_id'] ?? $userId}" />
                </div>


            <!--  列表的开始 -->

            <div class="save_or_no">
                <a  class="cirtain">
                    <input type="button" class="ajax-post" value="确定">
                </a>
                {include file="public/cancel_list" /}
            </div>
            </div>
        </form>
    </div>
    </div>
</div>

</div>
</div>

    <!-----获取经纬度的个数--->
    <input type="hidden" value="1" name="add_case_depart_lat">
    <!-----电子胶片--->
    <input type="hidden" value="1" name="add_record_depart_value">
    <input type="hidden" value="{$case_lat[0]['name'] ?? ''}" name="default_lat">
    <input type="hidden" value="{$case_depart[0]['name'] ??''}" name="default_part">


    {include file="public/footer"}

    <script>


        $(document).on("click","a.add_btn",function(){

            //获取pic_box的长度,添加id
            var num = $(".buwei_dec .pic_box").length;

            $.ajax(
                    {
                        url : "{:url('record/add_record_depart')}",
                        type : 'post',
                        data: {"num":num},
                        dataType : 'json',
                        success : function (result)
                        {
                            console.log(result)

                            $(".buwei_dec").append(result);
                            var value_num = Number(num+1);
                            console.log(value_num);
                            $("[name=add_record_depart_value]").val(value_num);

                        }


                    })
        })




    </script>

    <script src="__STATIC__/common/webuploader/webuploader.min.js"></script>
    <script>
        //图片上传
        var uploader1 = WebUploader.create({
            auto: true,
            swf:'__ASSETS__/lib/webuploader/Uploader.swf',
            server:'{:url("common/upload/uploadFile")}',
            pick:'#pic',
            fileVal:'pic',
            fileNumLimit:'3',
            duplicate :true

        })

        uploader1.on('uploadSuccess', function(file, response){
            //console.log(response);
            if (response.error == 0) {
                var html = '<div class="pic_dec">';
                html += '<img src="'+response.url+'"/>';
                html += '<input type="hidden" class="body_album" name="electronic_report[]" value="'+response.url+'"/>';
                html += '<em class="remove-img"></em>';
                html += '</div>'
                $('#img_box').append(html);
            }
        });


        uploader1.on( 'uploadError', function( file ) {
            console.log(file);
        });

        //删除图片
        $('body').on('click', '.remove-img', function(){
            $(this).parent().remove();
            uploader1.trigger('fileDequeued');
        })

    </script>

